<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <el-form
        :inline="true"
        :model="queryForm"
        size="small"
        class="u-text-center"
        style="display:none"
      >
        <el-form-item label="商品名称">
          <el-input v-model="queryForm.keyword" placeholder="输入商品标题查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getPageData(true)">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="商品名称" prop="goods_title"></el-table-column>
        <el-table-column label="商品规格" prop="attribute_names"></el-table-column>
        <el-table-column label="操作类型" prop="operate_str"></el-table-column>
        <el-table-column label="上次库存" prop="last_storage"></el-table-column>
        <el-table-column label="变化库存" prop="storage"></el-table-column>
        <el-table-column label="变化类型" prop="change_str"></el-table-column>
        <el-table-column label="说明" prop="remark_str"></el-table-column>
        <el-table-column label="备注信息" prop="remark"></el-table-column>
        <el-table-column label="操作时间" prop="add_time_str"></el-table-column>
      </el-table>

      <div class="u-mt-20 u-text-center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";

export default {
  mixins: [commonPage],
  props: {
    pid: {
      type: String
    },
    aid: {
      type: String,
      value:""
    },
    operate: {
      type: String
    }
  },
  data() {
    return {
      apiName: "goodsStore",
      apiPage: "list",
      queryForm: {
        id: "",
        aid: "",
        operate: "store",
        keyword: ""
      }
    };
  },
  methods: {
    beforeOnLoad() {
      this.queryForm.id = this.pid;
      this.queryForm.aid = this.aid;
      this.queryForm.operate = this.operate;
    }
  },
  watch: {
    pid: {
      handler(newVal, objVal) {
        if (newVal != objVal) {
          this.queryForm.id = newVal;
          this.getPageData(true);
        }
      }
    }
  }
};
</script>
